import React from 'react'
import { render } from 'react-dom'
import {Route, IndexRoute} from 'react-router';
import {combineReducers} from 'redux-immutable';


/**
 * 这里用来配置路由规则
 */
import App from './app/index';
import Dashboard from './dashboard/index';
import User from './user/components/index';
import Term from './term/components/index';
import Post from './post/components/index';

const routes = (
  <Route path="/" breadcrumbName="管理后台" component={App}>
    <IndexRoute breadcrumbName="控制面板" component={Dashboard}/>
    <Route path="user" breadcrumbName="用户管理" component={User} />
    <Route path="term" breadcrumbName="分类管理" component={Term} />
    <Route path="post" breadcrumbName="文章列表" getComponent={(nextState, cb) => {
        require.ensure([], require => {
            cb(null, require('./post/components/index').default);
        });
      }} >

      <Route path="trash" breadcrumbName="回收站文章" getComponent={(nextState, cb) => {
        require.ensure([], require => {
            cb(null, require('./post/components/index').default);
        });
      }} />

      <Route path="edit/:_id"  breadcrumbName="编辑文章" getComponent={(nextState, cb) => {
        require.ensure([], require => {
            cb(null, require('./post/components/PostDetail').default);
        });
      }}/>

    </Route>
    <Route path="post-new" breadcrumbName="添加文章" getComponent={(nextState, cb) => {
        require.ensure([], require => {
            cb(null, require('./post/components/PostDetail').default);
        });
    }}/>

  </Route>
);

/**
 * 这里用来load reducers
 */
import app from './app/reducer'; //app全局
import dashboard from './dashboard/reducer'; //面板首页
import user from './user/reducer'; //面板首页
import term from './term/reducer'; //面板首页
import post from './post/reducer'; //面板首页

const reducers = combineReducers({
  app,
  dashboard,
  user,
  term,
  post
});

/**
 * render document
 */
import Root from '../Root'
render(
  <Root routes={routes} reducers={reducers}/>,
  document.getElementById('layout')
);
